﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ColemanSoftware.Delicious.Modules.Data;
using ColemanSoftware.Delicious.Modules.DeliciousFactory;

namespace DeliciousFeederDemo
{
    /// <summary>
    /// Interaction logic for AddBookmark.xaml
    /// </summary>
    public partial class AddBookmark : UserControl
    {
        public AddBookmark()
        {
            InitializeComponent();
        }

        private void AddBookmarkButton_Click(object sender, RoutedEventArgs e)
        {
            if (!String.IsNullOrEmpty(BookmarkTextBox.Text))
            {
                string title = TitleTextBox.Text;
                string description = DescriptionTextBox.Text;
                string url = BookmarkTextBox.Text;
                List<Tag> tags = new List<Tag>();
                DateTime date = DateTime.Now;

                string filter = TagTextBox.Text.Contains(",")
                                 ? "," :
                                TagTextBox.Text.Contains(";")
                                ? ";" :
                                TagTextBox.Text.Contains("|")
                                ? "|" : "";

                if (String.IsNullOrEmpty(filter))
                {
                    UserNotification.NotificationText = "Please only use a comma, semicolon or pipe";
                    return;
                }


                tags = TagFactory.CreateTagFromString(TagTextBox.Text);
                Requestor req = new Requestor();
                string errors = req.AddBookmark(title, description, url, tags);

                if (errors != "done")
                {

                    UserNotification.TextColor = Brushes.Red;
                    UserNotification.NotificationText = "Unable to add bookmark, please try again later:\n Error for administrator: " + errors;
                }

                else
                {
                    UserNotification.TextColor = Brushes.Green;
                    UserNotification.NotificationText = "Bookmark Added sucessfully";
                    TitleTextBox.Text = "";
                    BookmarkTextBox.Text = "";
                    TagTextBox.Text = "";
                    TitleTextBox.Text = "";
                    DescriptionTextBox.Text = "";
                }
            }
        }
    }
}
